package com.example.project.controller;
import com.example.project.domain.entity.User;
import com.example.project.domain.response.Response;
import com.example.project.service.UserService;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/users")
@CrossOrigin(origins = "*")
@Tag(name = "用户管理", description = "用户相关的API操作")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping
    @Operation(summary = "创建新用户", description = "创建新用户")
    public Response<Void> createUser(@RequestBody User user) {
         return userService.createUser(user);
    }

    @GetMapping("/{id}")
    @Operation(summary = "获取用户信息", description = "根据ID查询用户信息")
    public Response<User> getUserById(@PathVariable String id) {
        return userService.getUserById(id);
    }

    @GetMapping
    @Operation(summary = "获取用户信息", description = "根据ThreadLocal查询用户信息")
    public Response<User> getUser(){
        return userService.getUser();
    }
}